package com.example.mypigcar.common.core;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

//统一返回结果的类
@Data
public class SR {

    @ApiModelProperty(value = "是否成功")
    private Boolean success;

    @ApiModelProperty(value = "返回码")
    private Integer code;

    @ApiModelProperty(value = "返回消息")
    private String msg;

    @ApiModelProperty(value = "返回数据")
    private Object data;

    //把构造方法私有
    private SR() {}

    //成功静态方法
    public static SR ok() {
        SR r = new SR();
        r.setSuccess(true);
        r.setCode(ResultCode.SUCCESS);
        r.setMsg("成功");
        return r;
    }

    //失败静态方法
    public static SR error() {
        SR r = new SR();
        r.setSuccess(false);
        r.setCode(ResultCode.ERROR);
        r.setMsg("失败");
        return r;
    }

    public SR success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public SR message(String message){
        this.setMsg(message);
        return this;
    }

    public SR code(Integer code){
        this.setCode(code);
        return this;
    }

    public SR data(Object value){
        this.data = value;
        return this;
    }



}
